package org.whatever.aha.zjut.platform.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.whatever.aha.zjut.platform.entity.AcademyAdmin;
import org.whatever.aha.zjut.platform.mapper.AcademyAdminMapper;
import org.whatever.aha.zjut.platform.service.project.ProjectService;
import org.whatever.aha.zjut.platform.vo.academy.HistoryVo;
import org.whatever.aha.zjut.platform.vo.academy.RecommendVo;

import java.util.List;

/**
 * @author Vc
 * @version 1.0
 * @Desc
 * @date 2021/11/02 0:09
 */
@Service
@RequiredArgsConstructor
public class AcademyAdminService {
    final AcademyAdminMapper academyAdminMapper;
    @Autowired
    @Lazy
    private ProjectService projectService;

    /**
     * 根据userId获得相应的academyId
     *
     * @param userId
     * @return
     */
    public int getAcademyIdByUserId(int userId){
        return academyAdminMapper.getAcademyIdByUserId(userId);
    }

    /**
     * 获取所有的院级管理员Id
     *
     * @return
     */
    public List<Object> getAdminList(){
        return academyAdminMapper.selectObjs(new QueryWrapper<AcademyAdmin>().select("user_id"));
    }

    /**
     * 获取未推荐项目，未审核排先
     *
     * @param academyId
     * @param compId
     * @param stageId
     * @return
     */
    public List<RecommendVo> getUnrecProjects(int academyId, int compId, int stageId) {
        return projectService.getUnrecProjects(academyId, compId, stageId);
    }

    /**
     * 获取普通推荐项目
     *
     * @param academyId
     * @param compId
     * @param stageId
     * @return
     */
    public List<RecommendVo> getNormalProjects(int academyId, int compId, int stageId) {
        return projectService.getNormalProjects(academyId, compId, stageId);
    }

    /**
     * 获取院级自评三等奖项目
     *
     * @param academyId
     * @param compId
     * @param stageId
     * @return
     */
    public List<RecommendVo> getAcademyThirdPrizeProjects(int academyId, int compId, int stageId) {
        return projectService.getAcademyThirdPrizeProjects(academyId, compId, stageId);
    }

    /**
     * 获取省级推荐项目
     *
     * @param academyId
     * @param compId
     * @param stageId
     * @return
     */
    public List<RecommendVo> getProvinceRecProjects(int academyId, int compId, int stageId) {
        return projectService.getProvinceRecProjects(academyId, compId, stageId);
    }

    /**
     * 获取校团委推荐项目
     *
     * @param academyId
     * @param compId
     * @param stageId
     * @return
     */
    public List<RecommendVo> getSchoolCommunityRecProjectInfo(int academyId, int compId, int stageId) {
        return projectService.getSchoolCommunityRecProjects(academyId, compId, stageId);
    }

    /**
     * 普通推荐项目
     *
     * @param projectId
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public Integer normalRecProject(int projectId) {
        return projectService.normalRecProject(projectId);
    }

    /**
     * 取消推荐
     *
     * @param projectId
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public Integer cancelRec(int projectId) {
        return projectService.cancelRec(projectId);
    }

    /**
     * 省级推荐
     *
     * @param projectId
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public Integer recProvinceProject(int projectId) {
        return projectService.recProvinceProject(projectId);
    }

    /**
     * 自评三等奖
     *
     * @param projectId
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public Integer academyThirdPrizeProject(int projectId) {
        return projectService.academyThirdPrizeProject(projectId);
    }

    /**
     * 增加一条记录
     *
     * @param userId
     * @param academyId
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public int addAcademyAdmin(int userId, int academyId){
        return academyAdminMapper.insert(new AcademyAdmin(userId, academyId));
    }

    /**
     * 删除一条记录
     *
     * @param userId
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public int deleteAcademyAdmin(int userId){
        return academyAdminMapper.delete(new QueryWrapper<AcademyAdmin>().eq("user_id", userId));
    }

    /**
     * 根据学院ID集合获取用户Id
     *
     * @param academyIdList
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public List<Object> getUserIdListByAcademyIdList(List<Integer> academyIdList){
        return academyAdminMapper.selectObjs(new QueryWrapper<AcademyAdmin>().in("academy_id", academyIdList));
    }

    /**
     * 更新学院管理员信息
     *
     * @param userId
     * @param academyId
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public int updateAcademyAdmin(int userId, int academyId){
        return academyAdminMapper.update(new AcademyAdmin(userId,academyId), new QueryWrapper<AcademyAdmin>().eq("user_id",userId));
    }

    /**
     * 根据比赛年份与赛事类型、学院Id获取学院赛事结果
     *
     * @param compYear
     * @param compType
     * @param academyId
     * @param stageId
     * @return
     */
    public List<HistoryVo> getHistory(int compYear, int compType, int academyId, int stageId){
        return projectService.getHistory(compYear, compType, academyId, stageId);
    }

    /**
     * 已审核接口
     *
     * @param projectId
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public int judgeProject(int projectId){
        return projectService.judgeProject(projectId);
    }

    /**
     * 增加院级管理员备注
     *
     * @param note
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public int addNote(int projectId, String note){
        return projectService.addNote(projectId, note);
    }

    /**
     * 获取院级管理员备注
     *
     * @param projectId
     * @return
     */
    public String getNote(int projectId){
        return projectService.getNote(projectId);
    }



}
